//
//  ShareView.m
//  Btpin
//
//  Created by Vic on 2019/4/27.
//  Copyright © 2019 Vic. All rights reserved.
//

#import "ShareView.h"
#import "ShareItemButton.h"

#define ShareViewBtnTag (6966)

@implementation ShareView

- (instancetype)initWithTarget:(id)target {
    self = [super init];
    if (self) {
        [self initUI];
        self.delegate = target;
    }
    return self;
}
- (void)initUI {
    self.frame = CGRectMake(0, 0, WIDTH, HEIGHT);
    self.backgroundColor = [UIColor colorWithWhite:0.01 alpha:0.5];
    [self addTarget:self action:@selector(cancelBtnTap) forControlEvents:UIControlEventTouchUpInside];
    [[UIApplication sharedApplication].keyWindow addSubview:self];
    
    UIView *bgView = [UIToolsControl initViewWithFrame:CGRectMake(0, HEIGHT-SIMEmojKeyBoardkBottomNOSafeArea_Height-160*Scale, WIDTH, 160*Scale) backgroundColor:COLOR_OF_WHITE];
    [self addSubview:bgView];
    
    NSArray *arr = @[@[@"share_weixin_haoyou", @"微信好友"], @[@"share_weixin_pengyou", @"微信朋友圈"], @[@"share_qq_haoyou", @"QQ好友"], @[@"share_qq_zone", @"QQ空间"]];
    CGFloat itemWidth = (WIDTH-20*Scale)*0.25;
    for (NSInteger i = 0; i < arr.count; i++) {
        ShareItemButton *btn = [[ShareItemButton alloc] initWithFrame:CGRectMake(10*Scale+itemWidth*i, 0, itemWidth, 120*Scale) imageName:arr[i][0] itemText:arr[i][1]];
        btn.tag = i+ShareViewBtnTag;
        [btn addTarget:self action:@selector(btnTap:) forControlEvents:UIControlEventTouchUpInside];
        [bgView addSubview:btn];
    }
    
    UIButton *cancelBtn = [UIToolsControl initButtonWithFrame:CGRectMake(0, 120*Scale, WIDTH, 40*Scale) imageName:nil target:self action:@selector(cancelBtnTap) title:@"取消" titleColor:THEMECOLOR_OF_TEXT_9a9a9a];
    cancelBtn.titleLabel.font = Font(Font_15);
    [bgView addSubview:cancelBtn];
    [cancelBtn borderColor:THEMECOLOR_OF_TEXT_cccccc borderWidth:lineH borderType:BorderSideTypeTop];
}
- (void)cancelBtnTap {
    if (self.delegate && [self.delegate respondsToSelector:@selector(shareViewCancel:)]) {
        [self.delegate shareViewCancel:self];
    }
}
- (void)btnTap:(ShareItemButton *)button {
    if (self.delegate && [self.delegate respondsToSelector:@selector(shareViewSelectItem:type:)]) {
        switch (button.tag-ShareViewBtnTag) {
            case 0: {
                [self.delegate shareViewSelectItem:self type:ShareTypeOfWXHaoyou];
            } break;
            case 1: {
                [self.delegate shareViewSelectItem:self type:ShareTypeOfWXPengyouquan];
            } break;
            case 2: {
                [self.delegate shareViewSelectItem:self type:ShareTypeOfQQ];
            } break;
            case 3: {
                [self.delegate shareViewSelectItem:self type:ShareTypeOfQQZone];
            } break;
            default:
                break;
        }
    }
}

@end
